package vm.project;

import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Folder;
import de.micromata.opengis.kml.v_2_2_0.GroundOverlay;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.KmlFactory;
import de.micromata.opengis.kml.v_2_2_0.LinearRing;
import de.micromata.opengis.kml.v_2_2_0.RefreshMode;
import de.micromata.opengis.kml.v_2_2_0.Style;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;


public class GestionKML {
    
    public void groundOverlay(String nom,String desc,String image,double dnorth,double dsouth,double deast,double dwest) throws FileNotFoundException{
        final Kml kml = KmlFactory.createKml();
        final GroundOverlay groundoverlay = kml.createAndSetGroundOverlay()

        .withName(nom)
        .withColor("9fffffff")
        .withDrawOrder(1);

        groundoverlay.createAndSetIcon()
        .withHref(image)
        .withRefreshMode(RefreshMode.ON_INTERVAL)
        .withRefreshInterval(86400d)
        .withViewBoundScale(0.75d);

        groundoverlay.createAndSetLatLonBox()
        .withNorth(dnorth)
        .withSouth(dsouth)
        .withEast(deast)
        .withWest(dwest)
        .withRotation(180);
        kml.marshal(new File(nom+".kml"));
    }
    
    public void placemark(String nom,ArrayList<Point> tablePoint) throws FileNotFoundException {
        placemark(nom, tablePoint,"7f000000");
    }
    
    public void placemark(String nom,ArrayList<Point> tablePoint,String couleur) throws FileNotFoundException{
        final Kml kml = KmlFactory.createKml();
        final Document document = kml.createAndSetDocument();
        final Style style = document.createAndAddStyle().withId("linestyleExample");

        style.createAndSetLineStyle()
                .withColor(couleur)
                .withWidth(8.0d);
        LinearRing lr = document.createAndAddPlacemark().withName(nom).withStyleUrl("#linestyleExample")
        .createAndSetPolygon().createAndSetOuterBoundaryIs().createAndSetLinearRing();
        for(Point p : tablePoint){
                       lr.addToCoordinates(p.getX(), p.getY());
         }
        kml.marshal(new File(nom+".kml"));
    }
    
    public void afficherTouteLesSations (Collection<StationsInfos> sations,String nom) throws FileNotFoundException {
        final Kml kml = KmlFactory.createKml();
        final Folder folder = kml.createAndSetFolder().withName(nom).withOpen(true);       
        for(StationsInfos si : sations){
            folder.createAndAddPlacemark().withName(si.getNom()).createAndSetPoint().addToCoordinates(si.getX()+","+si.getY());
        }
        kml.marshal(new File(nom+".kml"));   
    }
    
    public void afficherTouteLesPoints (Collection<Point> sations,String nom) throws FileNotFoundException {
        final Kml kml = KmlFactory.createKml();
        final Folder folder = kml.createAndSetFolder().withName(nom).withOpen(true);       
        for(Point si : sations){
            folder.createAndAddPlacemark().withName(Double.toString(si.getV())).createAndSetPoint().addToCoordinates(si.getX()+","+si.getY());
        }
        kml.marshal(new File(nom+".kml"));   
    }
    
    public void superMethode(){}
}
